package com.ryskoo.basicdata.weixin.repository;

import com.ryskoo.basicdata.weixin.domain.WeixinParamPO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

/**
 * @author BeHappy
 */
@Repository
public class WeixinParamJPAImpl extends BasicJPAImpl<WeixinParamPO> implements IWeixinParamRepository {
    /**
     * 通过商户id获取商户微信配置
     *
     * @param vendorId 商户id
     * @return 商户微信配置
     */
    @Override
    public WeixinParamPO getByVendorId(String vendorId) {
        String hql = "from WeixinParamPO where vendorId = :vendorId";
        Query query = getH4Session().createQuery(hql);
        query.setString("vendorId", vendorId);
        query.setMaxResults(1);
        return (WeixinParamPO) query.uniqueResult();
    }

    /**
     * 通过微信支付商户号获取商户微信配置
     *
     * @param payMchid 微信支付商户号
     * @return 商户微信配置
     */
    @Override
    public WeixinParamPO getByMchId(String payMchid) {
        String hql = "from WeixinParamPO where payMchid = :payMchid";
        Query query = getH4Session().createQuery(hql);
        query.setString("payMchid", payMchid);
        query.setMaxResults(1);
        return (WeixinParamPO) query.uniqueResult();
    }
}
